package com.wfk.mac.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wfk.entity.Items;
import com.wfk.h5.service.BrushService;
import com.wfk.mac.mapping.MappingUtils;
import com.wfk.service.IBaseInfoService;
import com.wfk.service.IItemsService;
import com.wfk.utils.ResponseData;

import cn.hutool.core.date.DateUtil;


@Controller
public class BrushController {

	@Autowired
	private IItemsService itemsService;
	@Autowired
	private BrushService brushService;
	@Autowired
	private IBaseInfoService baseInfoService;
	@RequestMapping(MappingUtils.itemsList)
	@ResponseBody
	public ResponseData itemsList() {
		String startTime = this.baseInfoService.getByKey("startTime");
		String endTime = this.baseInfoService.getByKey("endTime");;
		int hour = DateUtil.hour(new Date(), true);
		if(hour<Integer.parseInt(startTime)||hour>Integer.parseInt(endTime)) {
			return ResponseData.baseError("浏览时间"+startTime+"点到"+endTime+"点");
		}
		List<Items> itemsList = itemsService.itemsList();
		return ResponseData.ok().putDataValue("data", itemsList);
	}
	
	@RequestMapping(MappingUtils.itemDeila)
	@ResponseBody
	public ResponseData itemsOne() {
		Items itemsOne = itemsService.itemsOne();
		return ResponseData.ok().putDataValue("data", itemsOne);
	}
	
	
	@RequestMapping(MappingUtils.brush)
	@ResponseBody
	public ResponseData brush(Integer cid,Integer item) {
		try {
			return brushService.handleBrush(cid, item);
		}catch(Exception e) {
			e.printStackTrace();
			return ResponseData.baseServiceError("扫描失败");
		}
	}
	
}
